﻿using System;
using System.ComponentModel.Composition;
using System.Globalization;

using Caliburn.Micro;

using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Axes;

namespace DailyFx.Studio
{
	using DailyFx.UI;

	[Export(typeof(DailyFx.UI.IChartManager))]
	public class ChartManager : DailyFx.UI.ChartManager
	{
		public ChartManager ( )
		{
		}

		
	}

	[Export(typeof(DailyFx.UI.IChart))]
	public class CanvasImpl: DailyFx.UI.Canvas
	{
		public CanvasImpl( String title, BarSeries series )
		{
			// Title
			this.Title = title ;
			
			//
			Init( null );
			
			
			
			//plotModel.Axes.Add( timeAxis );

			
			//// Create the high-low series (markers are hidden by default)
			//var candleSeries = new CandleStickSeries( "BAR" ) 
			//{
			//	Color = OxyColors.SkyBlue,
			//	/*
			
			//	// Source Binding .
			//	//
			//		ItemsSource = series, 
			//	// Fields Binding .
			//	//
			//		DataFieldClose	= "LastPx",
			//		DataFieldHigh	= "High",
			//		DataFieldLow	= "Low",
			//		DataFieldOpen	= "Open",
			//		DataFieldX		= "Key",
			//	*/
			//};
			
			//plotModel.Series.Add( candleSeries );

			//// Notify this is changed .
			//this.Model = plotModel ;
			//this.MainImpl = TwoLineSeries ();

			//this.Charts.Add(new Chart() { ModelImpl = OneSeries() });
			//this.Charts.Add(new Chart() { ModelImpl = OneSeries() });
			//this.Charts.Add(new Chart() { ModelImpl = OneSeries() });
			//this.Charts.Add(new Chart() { ModelImpl = OneSeries() });
			//this.Charts.Add(new Chart() { ModelImpl = OneSeries() });
			//var x = new Chart() { ModelImpl = TwoLineSeries() };
			//x.ModelImpl.Axes[1].IsAxisVisible = true;
			//this.Charts.Add(x);

		}

		public void Init ( DailyFx.BarSeries series )
		{
 			// assert ( this.Charts.Count == 0)
			var chart = new MainChart( this.Title, 0 );
			this.Charts.Add( chart );
		}

		public void Add ( DailyFx.Index indicator )
		{
		}

		public static PlotModel OneSeries()
		{
			var model = new PlotModel() { LegendSymbolLength = 24 };
			model.PlotMargins = new OxyThickness(0);
			model.Axes.Add(new LinearAxis(AxisPosition.Left, -1, 71, "Y-Axis"));
			model.Axes.Add(a);
			a.TickStyle = TickStyle.Inside;
			a.FontSize = 10;
			
			var s1 = new LineSeries("Series 1")
			{
				Color = OxyColors.SkyBlue,
				MarkerType = MarkerType.Circle,
				MarkerSize = 6,
				MarkerStroke = OxyColors.White,
				MarkerFill = OxyColors.SkyBlue,
				MarkerStrokeThickness = 1.5
			};
			s1.Points.Add(new DataPoint(0, 10));
			s1.Points.Add(new DataPoint(10, 40));
			s1.Points.Add(new DataPoint(40, 20));
			s1.Points.Add(new DataPoint(60, 30));
			model.Series.Add(s1);
			return model;
		}
		static LinearAxis a =new LinearAxis(AxisPosition.Bottom, -1, 61);

		public static PlotModel TwoLineSeries()
		{
			var model = new PlotModel("Two LineSeries") { LegendSymbolLength = 24 };
			model.Axes.Add(new LinearAxis(AxisPosition.Left, -1, 71, "Y-Axis"));
			model.Axes.Add(a);
			var s1 = new LineSeries("Series 1")
			{
				Color = OxyColors.SkyBlue,
				MarkerType = MarkerType.Circle,
				MarkerSize = 6,
				MarkerStroke = OxyColors.White,
				MarkerFill = OxyColors.SkyBlue,
				MarkerStrokeThickness = 1.5
			};
			s1.Points.Add(new DataPoint(0, 10));
			s1.Points.Add(new DataPoint(10, 40));
			s1.Points.Add(new DataPoint(40, 20));
			s1.Points.Add(new DataPoint(60, 30));
			model.Series.Add(s1);

			var s2 = new LineSeries("Series 2")
			{
				Color = OxyColors.Teal,
				MarkerType = MarkerType.Diamond,
				MarkerSize = 6,
				MarkerStroke = OxyColors.White,
				MarkerFill = OxyColors.Teal,
				MarkerStrokeThickness = 1.5
			};
			s2.Points.Add(new DataPoint(0, 4));
			s2.Points.Add(new DataPoint(10, 32));
			s2.Points.Add(new DataPoint(40, 14));
			s2.Points.Add(new DataPoint(60, 20));
			model.Series.Add(s2);
			return model;
		}

	}
}
